package com.rc.saas.payment.unwxpay.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * SHA256加密器 <br/>
 * ClassName: SHA256Util <br/>
 * Function: TODO ADD FUNCTION. <br/>
 * date: 2018年5月17日 上午10:54:25 <br/>
 *
 * @author GuangMing
 * @email 1421769580@qq.com
 * @version
 * @since JDK 1.8
 */
public class SHA256Util {

    private static MessageDigest SHA256;

    static {
        try {
            SHA256 = MessageDigest.getInstance("SHA-256");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
    }

    public static synchronized String getSha256(String msg) {
        return getSha256(msg.getBytes());
    }

    public static synchronized String getSha256(byte[] msg) {
        SHA256.update(msg);
        return CodingUtil.bytesToHexString(SHA256.digest());
    }

}
